package gat.dto.res.tg.excel;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class OrderDiscountConverter implements Converter<Long> {
    @Override
    public WriteCellData convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value == null) {
            return new WriteCellData<>(BigDecimal.ZERO);
        }

        // 创建 BigDecimal 时先转为字符串避免精度问题
        BigDecimal original = new BigDecimal(value.toString());
        BigDecimal divisor = new BigDecimal("10000");

        // 除以 1,000,000 并保留6位小数，四舍五入
        return new WriteCellData<>(original.divide(divisor, 2, RoundingMode.HALF_UP));
    }

}
